package com.changgou.config.controller;
import com.changgou.entity.PageResult;
import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.config.service.FreightTemplateService;
import com.changgou.config.pojo.FreightTemplate;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@CrossOrigin
@RequestMapping("/freightTemplate")
public class FreightTemplateController {


    @Autowired
    private FreightTemplateService freightTemplateService;


    /**
     * 分页查询运费模板
     * @param current
     * @param pageSize
     * @return
     */
    @GetMapping("/findAllfreightTemplate/{current}/{pageSize}")
    public PageResult findAllfreightTemplate(@PathVariable int current,@PathVariable int pageSize ){
        Page<FreightTemplate> freightTemplates = freightTemplateService.freightTemplate(current, pageSize);

        return new PageResult<>(freightTemplates.getTotal(),freightTemplates.getResult());
    }

    /**
     * 添加运费模板
     * @param freightTemplate
     * @return
     */
    @PostMapping("/addFreightTemplate")
    public Result addFreightTemplate(@RequestBody FreightTemplate freightTemplate){
        freightTemplateService.addFreightTemplate(freightTemplate);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    //删除运费模板
    @GetMapping("/deleteFreightTemplate/{id}")
    public Result deleteFreightTemplate(@PathVariable int id){
        freightTemplateService.deleteFreightTemplate(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }
}
